<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<%@ page import="java.util.HashMap,
                 javax.servlet.http.*,
                 java.util.ArrayList,
                 com.scalar.chiptrack.utils.ConfigManager" %>


<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>

<chiptrack:checkLogon sourcePage="/baseProductList.do"/>

<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>

<HTML><HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>
<SCRIPT language="JavaScript" src="<%=chipTracContext%>/jsp/includes/scripts/validations.js">
</SCRIPT>
<SCRIPT>
function cancel() 
{
	document.testprocess.action ="<%=chipTracContext%>/baseProductList.do";
	document.testprocess.submit();
}

function addMoreActivate(name,no)
{
	check    = eval('document.testprocess.'+name+'addMorecheck'+no+'.checked');	
	objname     = eval('document.testprocess.'+name+'addMorename'+no);	
	sequence = eval('document.testprocess.'+name+'addMoreseq'+no);

	if(check==true)
	{
		objname.disabled=false;
		sequence.disabled=false;
		var top = new Number(0);
		for(var x=0; x < document.testprocess.testCount.value; x++)
		{
			temp = eval('document.testprocess.'+name+'seq'+x);
			if( parseInt(temp.value) > parseInt(top) )
			{
				top = temp.value;
			}
		
		}

		var addMoreCount = eval('document.testprocess.'+name+'addMoreCount');
		
		if( addMoreCount.value > 1)
		{
			for( var y=1 ; y <= addMoreCount.value ; y++ )
			{
				temp = eval('document.testprocess.'+name+'addMoreseq'+y);
				if( parseInt(temp.value) > parseInt(top) )
				{	
					top = parseInt(temp.value);
				}
			}
		}
		sequence.value =  parseInt(top) + 1;
	}
	else
	{
		var myVal = eval('document.testprocess.'+name+'addMoreseq'+no).value;
		objname.disabled=true;
		sequence.disabled=true;
	
		objname.value   ='';
		sequence.value  ='';

		if( myVal != null && myVal > 0 )
		{
			for(var x=0; x < document.testprocess.testCount.value; x++)
			{
				temp = eval('document.testprocess.'+name+'seq'+x);
				if( parseInt(temp.value) > parseInt(myVal) )
				{
					temp.value = parseInt(temp.value)-1;
				}
			}
			
			var addMoreCount = eval('document.testprocess.'+name+'addMoreCount');
			
			if( addMoreCount.value > 1)
			{
				for( var y=1 ; y <= addMoreCount.value ; y++ )
				{
					temp = eval('document.testprocess.'+name+'addMoreseq'+y);
					if( parseInt(temp.value) > parseInt(myVal) )
					{	
						temp.value = parseInt(temp.value)-1;
					}
				}
			}
			else
			{
				temp = eval('document.testprocess.'+name+'addMoreseq1');
				if( parseInt(temp.value) > parseInt(myVal) )
				{	
					temp.value = parseInt(temp.value)-1;
				}
			}
		}

	 }

}


function activate(val,count){

	check = eval('document.testprocess.'+val+'check'+count+'.checked');	
	vall   = eval('document.testprocess.'+val+'seq'+count);
	
	if(check==true)	
	{
		vall.disabled=false;
		var top = new Number(0);
		for(var x=0; x < document.testprocess.testCount.value; x++)
		{
			temp = eval('document.testprocess.'+val+'seq'+x);
			if( parseInt(temp.value) > parseInt(top) )
			{
				top = parseInt(temp.value);
			}
		
		}
		var addMoreCount = eval('document.testprocess.'+val+'addMoreCount');
		
		if( addMoreCount.value > 1)
		{
			for( var y=1 ; y <= addMoreCount.value ; y++ )
			{
				temp = eval('document.testprocess.'+val+'addMoreseq'+y);
				if( parseInt(temp.value) > parseInt(top) )
				{	
					top = parseInt(temp.value);
				}
			}
		}
		else
		{
			temp = eval('document.testprocess.'+val+'addMoreseq1');
			if( parseInt(temp.value) > parseInt(top) )
			{	
				top = parseInt(temp.value);
			}
		}
		vall.value = parseInt(top) + 1;
	}
	else
	{
		var myVal = eval('document.testprocess.'+val+'seq'+count).value;
		vall.value='';
		vall.disabled=true;
		
		if( myVal != null && myVal > 0 )
		{
			//alert("I need to validate this");
			for(var x=0; x < document.testprocess.testCount.value; x++)
			{
				temp = eval('document.testprocess.'+val+'seq'+x);
				if( parseInt(temp.value) > parseInt(myVal) )
				{
					temp.value = parseInt(temp.value)-1;
				}
			}
			
			var addMoreCount = eval('document.testprocess.'+val+'addMoreCount');
			
			if( addMoreCount.value > 1)
			{
				for( var y=1 ; y <= addMoreCount.value ; y++ )
				{
					temp = eval('document.testprocess.'+val+'addMoreseq'+y);
					if( parseInt(temp.value) > parseInt(myVal) )
					{	
						temp.value = parseInt(temp.value)-1;
					}
				}
			}
			else
			{
				temp = eval('document.testprocess.'+val+'addMoreseq1');
				if( parseInt(temp.value) > parseInt(myVal) )
				{	
					temp.value = parseInt(temp.value)-1;
				}
			}
		}
		//vall.value='';
		//vall.disabled=true;
	} 
} 

function func() 
{
    var errors = ''; 
	var errorId = '';

	if ( typeof document.testprocess.assyProductNames.length == 'undefined')
	{
		var temp = document.testprocess.assyProductNames.value;
		var testCount = document.testprocess.testCount.value;
		var addmoreCnt = eval('document.testprocess.'+ temp +'addMoreCount').value;
		testSeqs = new Array( parseInt(testCount) + parseInt(addmoreCnt) );
		var count = 0;
		//var seqCount = 0;
		//alert(addmoreCnt+"        "+temp);
		for(var i =0 ; i < testCount ; i++ )
		{
			testSeqs[i] = eval('document.testprocess.'+temp+'seq'+i).value ;
			if( chkNumZero(testSeqs[i],"Test sequence ","N")==false )
			{
				errors = '<li> '+errMsg;
				errorId = 'errors0';
				break;
			}
			
			if (testSeqs[i].trim().length > 0 )
			{
				count++;
			}
			//seqCount = i;
		}
			
	/*	for( var y=1 ; y < parseInt(addmoreCnt)+1 ; y++ )
		{
			alert("OK");
			alert('document.testprocess.'+temp+'addMorecheck'+y);
			var tempAddmore = eval('document.testprocess.'+temp+'addMoreseq'+y).value ;
			testSeqs[seqCount] = tempAddmore;
			if( chkNumZero( tempAddmore , "Test sequence " , "N" ) == false )
			{
				errors = '<li> '+errMsg;
				errorId = 'errors0';
				break;
			}
			
			if (testSeqs[seqCount].trim().length > 0 )
			{
				count++;
			}
			seqCount++;
		}
		assyx295addMorename1    assyx295addMorecheck1
		alert(count); */

		for(var j = testCount ; j < parseInt(testCount)+parseInt(addmoreCnt) ; j++ )
		{
			testSeqs[j] = eval('document.testprocess.'+temp+'addMoreseq'+(parseInt(j)-parseInt(testCount)+1)).value;
			var addMoreChk = eval('document.testprocess.'+temp+'addMorecheck'+(parseInt(j)-parseInt(testCount)+1)).checked;
			var addMoreName = eval('document.testprocess.'+temp+'addMorename'+(parseInt(j)-parseInt(testCount)+1)).value;
			//alert(addMoreChk);
			if( chkNumZero(testSeqs[j],"Test sequence ","N")==false )
			{
				errors = '<li> '+errMsg;
				errorId = 'errors0';
				break;
			}

			if (testSeqs[j].trim().length > 0 )
			{
				count++;
			}

			if(addMoreChk+""=='true')
			{
				//alert("Ok");
				if( addMoreName != null && addMoreName.length < 1 )
				{
					errors = '<li> Test name cannot be empty ';
					errorId = 'errors0';
				}
			}

		}

		if( count==0 )
		{
			errors = '<li> Please select atleast one test ';
			errorId = 'errors0';
		}
		
		if(errors != '')
		{
			var pa=document.getElementById("errors0");
			pa.innerHTML = errors;
			location = "#errors0" ;
			return;
		}


	/*	if(errors != '')
		{
			var pa=document.getElementById("errors0");
			pa.innerHTML = errors;
			location = "#errors0" ;
			return;
		} */

		xyz:

		for(var x = 0 ; x < testSeqs.length-1 ; x++ )
		{
			if( testSeqs[x].trim() != '' )
			{
				for(var y = x+1 ; y < testSeqs.length ; y++ )
				{
					if( testSeqs[y].trim() != '' )
					{
						if( parseInt(testSeqs[x]) == parseInt(testSeqs[y]) )
						{
							errors =  "<li> Two tests cannot have the same test sequence";
							//alert(temp);
							//errorId = temp+'loc';
							errorId = 'errors0';
							//alert(errorId);
							break xyz;
						}
					}
				}
			}
		}
		
		if(errors != '')
		{
			var pa=document.getElementById(errorId);
			pa.innerHTML = errors;
			location = "#"+errorId;
			return;
		}
	}
	else
	{
		for( var p=0 ; p < document.testprocess.assyProductNames.length ; p++ )
		{
			var temp = document.testprocess.assyProductNames[p].value;
			var testCount = document.testprocess.testCount.value;
			var addmoreCnt = eval('document.testprocess.'+ temp +'addMoreCount').value;
			testSeqs = new Array( parseInt(testCount) + parseInt(addmoreCnt) );
			var count = 0;

			
			for(var i =0 ; i < testCount ; i++ )
			{
				testSeqs[i] = eval('document.testprocess.'+temp+'seq'+i).value ;
				if( chkNumZero(testSeqs[i],"Test sequence ","N")==false )
				{
					errors = '<li> '+errMsg;
					errorId = 'errors'+p;
					break;
				}

				if (testSeqs[i].trim().length > 0 )
				{
					count++;
				}
			}

			for(var j = testCount ; j < parseInt(testCount)+parseInt(addmoreCnt) ; j++ )
			{
				testSeqs[j] = eval('document.testprocess.'+temp+'addMoreseq'+(parseInt(j)-parseInt(testCount)+1)).value;
				var addMoreChk = eval('document.testprocess.'+temp+'addMorecheck'+(parseInt(j)-parseInt(testCount)+1)).checked;
				var addMoreName = eval('document.testprocess.'+temp+'addMorename'+(parseInt(j)-parseInt(testCount)+1)).value;

				if( chkNumZero(testSeqs[j],"Test sequence ","N")==false )
				{
					errors = '<li> '+errMsg;
					errorId = 'errors'+p;
					break;
				}
				if (testSeqs[j].trim().length > 0 )
				{
					count++;
				}

				if(addMoreChk+""=='true')
				{	
					if( addMoreName != null && addMoreName.length < 1 )
					{
						errors = '<li> Test name cannot be empty ';
						errorId = 'errors'+p;
					}
				}

			}

			if( count==0 )
			{
				errors = '<li> Please select atleast one test ';
				errorId = 'errors'+p;
			}

			if(errors != '')
			{
				for(var z=0 ; z < document.testprocess.assyProductNames.length ; z++)
				{	
					paa=document.getElementById("errors"+z);
					paa.innerHTML = "";
				}
				var pa=document.getElementById(errorId);
				pa.innerHTML = errors;
				location = "#"+errorId;
				return;
			}
			
			
		
		/*	if(errors != '')
			{
				for(var z=0 ; z < document.testprocess.assyProductNames.length ; z++)
				{	
					paa=document.getElementById("errors"+z);
					paa.innerHTML = "";
				}
				var pa=document.getElementById(errorId);
				pa.innerHTML = errors;
				location = "#"+errorId;
				return;
			}  */

			xyz1:
			for(var x = 0 ; x < testSeqs.length-1 ; x++ )
			{
				if( testSeqs[x].trim() != '' )
				{
					for(var y = x+1 ; y < testSeqs.length ; y++ )
					{
						if( testSeqs[y].trim() != '' )
						{
							if( parseInt(testSeqs[x]) == parseInt(testSeqs[y]) )
							{
								errors =  "<li> Two tests cannot have the same test sequence";
								//errorId = temp+'loc';
								errorId = 'errors'+p;
								break xyz1;
							}
						}
					}
				}
			}
		}
	}

	if(errors != '')
	{
		var pa=document.getElementById(errorId);
		//var paa;
		for(var z=0 ; z < document.testprocess.assyProductNames.length ; z++)
		{	
			paa=document.getElementById("errors"+z);
			paa.innerHTML = "";
		}
		pa.innerHTML = errors;
		location = "#"+errorId;
		return;
	}

	document.testprocess.submit();
}


if (document.layers)
  window.setResizable(false);
  var c = 0;

function addMore(test) {

objVal   =eval('document.testprocess.'+test+'addMoreCount');
var addMoreCount = objVal.value;
addMoreCount = parseInt(addMoreCount)+1;
objVal.value = addMoreCount;

var htmltext = ' <table border="0" width="90%"><tr><td><font class="NArialL"> ';
    htmltext +=' <input type="checkbox" name='+test+'addMorecheck'+addMoreCount;
	htmltext +=' onClick="addMoreActivate('+"'"+test+"'"+','+"'"+addMoreCount+"'"+');">';
	htmltext +=' <input type="text" name='+test+'addMorename'+addMoreCount;
	htmltext +=' size="20" class="txfield" disabled></td><td align="center">';
	htmltext +=' <input type="text" name='+test+'addMoreseq'+addMoreCount+' size="4" class="txfield" '; 
	htmltext +=' disabled></td></tr></table>';

var pa=document.getElementById('font'+test);
pa.insertAdjacentHTML('BeforeEnd',htmltext);

}

</SCRIPT>


<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type=text/css rel=stylesheet>

<META content="MSHTML 5.50.4807.2300" name=GENERATOR></HEAD>

<BODY bgColor=#ffffff leftMargin=0 topMargin=0 marginheight="0" marginwidth="0">

<html:form name="testprocess" type="com.scalar.chiptrack.operations.process.forms.TestProcessSplitForm" action="/testprocesssplit"> 

<!-- Top Header Start-->

<%@ include file="/jsp/includes/header.jsp" %>

<!-- Top Header End-->


<% HttpSession ses = request.getSession(true); 

   String baseProductName = (String) ses.getAttribute("baseProductName");

   String [] assyProducts =(String [])ses.getAttribute("assemblyProducts");

   String [] fabProducts =(String [])ses.getAttribute("fabProduct");

   ArrayList assemblyTrackList=(ArrayList)ses.getAttribute("assemblyTrackList");

   HashMap assyHash = (HashMap)ses.getAttribute("assemblyHash");

   String  assyProduct = "";

   ArrayList testNameList = (ArrayList)ses.getAttribute("testNames");

  
%>

<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
  <TBODY>
  <TR>
	<TD width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>

<!-- Side Navigation start -->

<%@ include file="/jsp/operations/operations_menu.jsp" %>

	</TD>
<!-- end of the side navigations -->

<TD bgcolor="#ffffff">
<IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></TD>
<TD bgcolor="#ffffff"><IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></TD>
<TD valign="top" width="100%">

<IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=500 border=0>
<BR>
<!-- from here your body starts -->


<center><span class="NArialW">Test Process Setup</span></center>
<img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20>


<table border="0" width="90%" align=right>
	<tr><td colspan=5 class="NArialL" align="left"><font color="FF0000"><FONT id="errors"></FONT></font></TD></TR>
	<tr><td colspan=5 class="NArialL" align="left"><font color="FF0000"><chiptrack:errors styleClass="NArialL"/></font></TD></TR>
    <tr><td colspan=2><font class="NArialL">Please enter the optional tests you want to do for these products
    	</font></td>  </tr>
		<input type="hidden" name="testCount" value="<%=testNameList.size()%>">
    <tr><td colspan=2><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>

	<% for(int i=0;i<assemblyTrackList.size();i++ )
	{
		assyProduct =	(String)assyHash.get(assemblyTrackList.get(i));
			
		if(!assyProduct.equals(""))
		{	 %>
	<tr>    <a name="#errors<%=i%>"/>
		<td colspan=5 class="NArialL" align="left"><font color="FF0000"><FONT id="errors<%=i%>"></FONT></font></TD></TR>
	<tr><td><font class="NArialL" valign=top>Assembly Product Name : <%=assyProduct%></font>
    	<br>		
	</td>
    <td>
   	 <table border="0" width="100%" align=left>
   	 <tr><td class="NArialL"><u>Test Name</u></td><td class="NArialL"><u>Sequence</u></td></tr>
	
	<input type="hidden" name="assyProductNames" value="assy<%=assyProduct.charAt(0)%><%=assemblyTrackList.get(i)%>">
	
	<% for(int k=0; k < testNameList.size(); k++) { %>
  	 <tr><td><font class="NArialL">
  
    <input type="checkbox" name="assy<%=assyProduct.charAt(0)%><%=assemblyTrackList.get(i)%>check<%=k%>"  onClick="activate('assy<%=assyProduct.charAt(0)%><%=assemblyTrackList.get(i)%>','<%=k%>');"><%=testNameList.get(k)%></td>
     <td>
	<input type="text" name="assy<%=assyProduct.charAt(0)%><%=assemblyTrackList.get(i)%>seq<%=k%>"
		size="4" class="txfield" disabled value=""></td></tr>
	              <%}%>
   	<tr>
    <td><font class="NArialL">
    <input type="checkbox" name="assy<%=assyProduct.charAt(0)%><%=assemblyTrackList.get(i)%>addMorecheck1"  onClick="addMoreActivate('assy<%=assyProduct.charAt(0)%><%=assemblyTrackList.get(i)%>','1');">
	<input type="text" name="assy<%=assyProduct.charAt(0)%><%=assemblyTrackList.get(i)%>addMorename1" size="20" class="txfield" value="" disabled></td>
    <td><input type="text" name="assy<%=assyProduct.charAt(0)%><%=assemblyTrackList.get(i)%>addMoreseq1" size="4" class="txfield" value="" disabled></td>
    </tr>

	<tr><td colspan="2"><font id=fontassy<%=assyProduct.charAt(0)%><%=assemblyTrackList.get(i)%>></font></td></tr>


	
    <tr><td colspan=2><a href="javascript:addMore('assy<%=assyProduct.charAt(0)%><%=assemblyTrackList.get(i)%>')">
		<img src="<%=chipTracContext%>/jsp/includes/images/addmore.gif" border="0"></td></tr>
    </table>
    </tr>
	<tr><td colspan=2><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>
	<tr><td colspan=2><font class="NArialL">Would you like to keep the products in the CLASS STORE after Test
	    	</font></td>  </tr>
	<tr><td colspan=2><font class="NArialL">
	<input type="radio" name="assy<%=assyProduct.charAt(0)%><%=assemblyTrackList.get(i)%>wafer" value="0">Yes &nbsp;&nbsp;&nbsp;
	<input type="radio" name="assy<%=assyProduct.charAt(0)%><%=assemblyTrackList.get(i)%>wafer" value="1" checked>No
	    	</font></td>  </tr>
	<tr><td colspan=2><HR width="100%" noShade SIZE=1></td></tr>
	<tr><td colspan=2><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>
    <input type="hidden" name="assy<%=assyProduct.charAt(0)%><%=assemblyTrackList.get(i)%>addMoreCount" value="1">
 
     <%		
						 

				}
			
					
    }	
	
	%>


	<tr><td colspan=2><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20></td></tr>
	<tr>
      <td colspan=2 align=center>
      <chiptrack:restrictedLink functionality='<%=Functionality.PRODUCT_SETUP%>' action='<%=User.USER_ACTION_MODIFY%>' href='javascript:func();' onmouseover="window.status='Click here to save the Test Process';return true" onmouseout="window.status='';return true">
	  <img border="0" src="<%=chipTracContext%>/jsp/includes/images/next.gif"></chiptrack:restrictedLink>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <chiptrack:restrictedLink functionality='<%=Functionality.PRODUCT_SETUP%>' action='<%=User.USER_ACTION_MODIFY%>' href='javascript:cancel();' onmouseover="window.status='Click here to return to Product List';return true" onmouseout="window.status='';return true">
	  <img border="0" src="<%=chipTracContext%>/jsp/includes/images/cancel.gif"></chiptrack:restrictedLink></td>
    </tr>
</table>


<!-- till here -->
<BR><BR><BR></TD>
<TD bgcolor="#ffffff"><IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1></TD>
</TR>
</TABLE>

<!-- Footer starts here -->

<%@ include file="/jsp/includes/footer.jsp" %>

<!-- footer end here -->
</html:form>
</BODY>
</html>
